package com.chris.blog.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.chris.blog.dao.BlogDao;
import com.chris.blog.entity.po.BlogPO;
import com.chris.blog.service.BlogService;
import com.github.pagehelper.Page;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
@Service
public class BlogServiceImpl implements BlogService {

    @Resource
    private BlogDao blogDAO;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int deleteByPrimaryKey(Integer id) {
        return blogDAO.deleteByPrimaryKey(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insert(BlogPO record) {
        return blogDAO.insert(record);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insertSelective(BlogPO record) {
        return blogDAO.insertSelective(record);
    }

    @Override
    public BlogPO selectByPrimaryKey(Integer id) {
        return blogDAO.selectByPrimaryKey(id);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateByPrimaryKeySelective(BlogPO record) {
        return blogDAO.updateByPrimaryKeySelective(record);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateByPrimaryKey(BlogPO record) {
        return blogDAO.updateByPrimaryKey(record);
    }

    public int count(String uid) {
        return blogDAO.count(uid);
    }

    public Page<BlogPO> findAllByUIdDesc(String uid) {
        return blogDAO.findAllByUIdDesc(uid);
    }

    public Page<BlogPO> findAllDesc() {
        return blogDAO.findAllDesc();
    }

    public BlogPO findOneByBid(Long bid) {
        QueryWrapper<BlogPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("bid", bid);
        BlogPO blogPO = blogDAO.selectOne(queryWrapper);
        return blogPO;
    }

    @Override
    public Page<BlogPO> findAllByCIdDesc(int cid) {
        return blogDAO.findAllByCIdDesc(cid);
    }

}
